package com.recording.system.sensor;

import java.util.ArrayList;

import com.recording.system.events.RecordingSystemEvent;
import com.recording.system.events.RecordingSystemEventKind;
import com.recording.system.signalsource.SignalSource;

public class SpeedSensor extends AbstractSensor{

	public static final String SPEED_DOWN = "Speed down";
	public static final String SPEED_UP = "Speed up";
	public static final int minSpeedThreshold = 1;

	public SpeedSensor(int sourceId) {
		super(sourceId);
	}
	private double speed = 0;

	@Override
	public void readSignalSource(SignalSource source,
			ArrayList<RecordingSystemEvent> res) {
		double newSpeed = source.getValue();
		if (Math.abs(newSpeed - speed) >= minSpeedThreshold)
		{
			RecordingSystemEvent event;
			if (newSpeed > speed)
			{
				event = new RecordingSystemEvent(RecordingSystemEventKind.SPEED_UP, SPEED_UP);
			}
			else
			{
				event = new RecordingSystemEvent(RecordingSystemEventKind.SPEED_DOWN, SPEED_DOWN);
			}
			res.add(event);
			speed = newSpeed;
		}
		
	}

}
